﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Office;
using Extensions;
namespace Dashboard
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent(); 
            titleBar.MouseLeftButtonDown += (o, e) => DragMove();
        }
        
        private void textBox2_OnKeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (Validation())
                {
                    listBox1.Items.Add(textBox2.Text);
                    textBox2.Text = "";
                }
            }
        }

        private bool Validation() {
            bool status = true;

            if (!textBox2.Text.IsNotNullAndEmpty())
            {
                MessageBox.Show("hey you!!, dont try with empty value buddy...");
                status = false;
            }

            if (status) {
                CreateTask();
            }

            return status;
        }

        private void CreateTask() {
            
            Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); // creates a new appointment
            oAppointment.Subject = textBox2.Text; // set the subject
            oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body
            oAppointment.Location = "Nicks Desk!"; // set the location
            if (textBox3.Template.IsNotNullAndEmpty())
                oAppointment.Start = DateTime.Now.AddDays(textBox3.Text.ToInt());
            else
                oAppointment.Start = DateTime.Now;
            oAppointment.End = DateTime.Now.AddDays(2); // End date 
            oAppointment.ReminderSet = true; // Set the reminder
            oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
            oAppointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; // appointment importance
            oAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
            oAppointment.Save();
            
            //Microsoft.Office.Interop.Outlook.MailItem mailItem = oAppointment.ForwardAsVcal(); 
            //// email address to send to 
            //mailItem.To = "mailto:me@decodedsolutions.co.uk";
            //// send 
            //mailItem.Send(); 
        }
    }
}
